#ifndef WIDGETTREE_H
#define WIDGETTREE_H

#include <QDomDocument>
#include <QHash>
#include <QIcon>
#include <QTreeWidget>

class WidgetTree : public QTreeWidget
{
    Q_OBJECT

public:
    WidgetTree(QWidget *parent = 0);

    bool readFile(const QString &fileName);
    bool writeFile(const QString &fileName);
    bool newFile(void);

    QTreeWidgetItem *createItem(const QDomElement &element,
                                QTreeWidgetItem *parentItem = 0);
    void setCurrentItem(QTreeWidgetItem *item);

    QDomElement createElement(const QString &tagName);
    void deleteItemElement(QTreeWidgetItem *item, const QDomElement &element);
    void addElement(const QDomElement &element);

    void parseWindowElement(QDomElement &element);
    void parseTabElement(QDomElement &element, QTreeWidgetItem *parentItem);
    void parseButtonElement(QDomElement &element, QTreeWidgetItem *parentItem);

private slots:
    void updateElement(QTreeWidgetItem *item, int column);

private:
    QDomDocument domDocument;
    QHash<QTreeWidgetItem *, QDomElement> domElementForItem;

signals:
    void createWindow(WidgetTree *tree, QDomElement &element, QTreeWidgetItem *item);
    void createTab(WidgetTree *tree, QDomElement &element, QTreeWidgetItem *item);
    void createButton(WidgetTree *tree, QDomElement &element, QTreeWidgetItem *item);
    void modified();

public slots:
    void somethingChanged();
};

#endif // WIDGETTREE_H
